package com.bazaaroid.mobile.db.model.partner;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.mobile.db.model.AbstractModel;
//import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Product extends AbstractModel {

	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private double price;
	@Persistent
	private String currency;
	@Persistent
	private Partner partner;
	@Persistent(defaultFetchGroup = "true")
	private Integer discount;
	@Persistent
    private Set<Location> locations = new HashSet<Location>();
	@Persistent
    private Set<Integer> categories = new HashSet<Integer>();
	@Persistent
    private Set<Integer> tags = new HashSet<Integer>();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Integer getDiscount() {
		return discount;
	}

	public void setDiscount(Integer discount) {
		this.discount = discount;
	}

	public Partner getPartner() {
		return partner;
	}

	public void setPartner(Partner partner) {
		this.partner = partner;
	}

	public Set<Location> getLocations() {
		return locations;
	}

	public void setLocations(Set<Location> locations) {
		this.locations = locations;
	}

	public void addLocation(Location location) {
	    locations.add(location);
	    //location.getProducts().add(getKey());
	}

	public void removeLocation(Location location) {
		locations.remove(location);
	    //location.getProducts().remove(getKey());
	}

	public Set<Integer> getCategories() {
		return categories;
	}

	public void setCategories(Set<Integer> categories) {
		this.categories = categories;
	}

	public void addCategory(Category category) {
	    categories.add(category.getKey());
	    category.getProducts().add(getKey());
	}

	public void removeCategory(Category category) {
		categories.remove(category.getKey());
	    category.getProducts().remove(getKey());
	}

	public Set<Integer> getTags() {
		return tags;
	}

	public void setTags(Set<Integer> tags) {
		this.tags = tags;
	}

	public void addTag(Tag tag) {
	    tags.add(tag.getKey());
	    tag.getProducts().add(getKey());
	}

	public void removeTag(Tag tag) {
		tags.remove(tag.getKey());
	    tag.getProducts().remove(getKey());
	}
}
